package com.example.lj.uav.view;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.lj.uav.MyApplication;
import com.example.lj.uav.R;
import com.example.lj.uav.widget.CommomDialog;
import com.example.lj.uav.view.base.BaseActivity;
import com.example.lj.uav.widget.LoadingDialog;

import dji.common.error.DJIError;
import dji.common.util.CommonCallbacks;
import dji.sdk.useraccount.UserAccountManager;

public class SettingActivity extends BaseActivity implements View.OnClickListener {

    private View v_portrait;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        ((TextView) findViewById(R.id.setting_tv_about)).setText("关于" + getResources().getString(R.string.app_name));
        ((TextView) findViewById(R.id.setting_tv_name)).setText(MyApplication.accountName);
        findViewById(R.id.setting_fl_back).setOnClickListener(this);
        findViewById(R.id.setting_ll_private).setOnClickListener(this);
        findViewById(R.id.setting_ll_contact).setOnClickListener(this);
        findViewById(R.id.setting_ll_about).setOnClickListener(this);
        findViewById(R.id.setting_tv_logout).setOnClickListener(this);
        v_portrait = findViewById(R.id.setting_v_portrait);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.setting_fl_back:
                finish();
                break;
            case R.id.setting_ll_private:
                toAct(PrivacyActivity.class);
                break;
            case R.id.setting_ll_contact:
                toAct(ContentActivity.class, "联系我们");
                break;
            case R.id.setting_ll_about:
                toAct(AboutActivity.class);
                break;
            case R.id.setting_tv_logout:
                new CommomDialog(this, R.style.commondialog, "确定退出当前登录用户吗？",
                        new CommomDialog.OnCloseListener() {
                            @Override
                            public void onClick(CommomDialog dialog, boolean confirm) {
                                if (confirm) {
                                    final LoadingDialog ld = LoadingDialog.getInstance(SettingActivity.this);
                                    ld.show();
                                    UserAccountManager.getInstance().logoutOfDJIUserAccount(new CommonCallbacks.CompletionCallback() {
                                        @Override
                                        public void onResult(DJIError djiError) {
                                            if (djiError == null) {
                                                showToast("已退出当前用户");
                                                toAct(LoginActivity.class, true);
                                            } else {
                                                showToast(djiError.getDescription());
                                            }
                                            ld.dismiss();
                                        }
                                    });
                                }
                                dialog.dismiss();
                            }
                        }).setTitle("提示").show();
                break;

        }
    }
}
